package de.hdodenhof.circleimageview.sample.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import de.hdodenhof.circleimageview.CircleImageView;
import de.hdodenhof.circleimageview.sample.R;

import static de.hdodenhof.circleimageview.sample.R.id.image1;

/**
 * A placeholder fragment containing a simple view.
 */
public class MainFragment extends Fragment {

    private static final String ARG_SECTION_NUMBER = "section_number";


    public static MainFragment newInstance(int index) {
        MainFragment fragment = new MainFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(ARG_SECTION_NUMBER, index);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_main, container, false);
        final CircleImageView imageView1 = root.findViewById(image1);
        Glide.with(this.getContext())
                .load("https://goss1.cfp.cn/creative/vcg/800/version23/VCG4189003084.jpg?x-oss-process=image/format,jpg/interlace,1")
                .placeholder(R.drawable.hugh)
                .into(imageView1);
        root.findViewById(R.id.btnShowCircle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView1.setDisableCircularTransformation(!imageView1.isDisableCircularTransformation());
                imageView1.invalidate();
            }
        });

        root.findViewById(R.id.btnBorder).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView1.setBorderOverlay(!imageView1.isBorderOverlay());
                imageView1.invalidate();
            }
        });
        root.findViewById(R.id.btnShape).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView1.setShapeType((imageView1.getShapeType() + 1)%3);//循环设置0，1，2
                imageView1.invalidate();
            }
        });
        return root;
    }



}